package com.example.dzbsh.controller;

import com.example.dzbsh.service.JiashuService;
import com.example.dzbsh.util.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("jiashu")
public class JiashuController {

    @Resource
    JiashuService ddService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    
    @RequestMapping("find_by_deptid")
    public JsonResult<?> findBydeptId(
            @RequestParam("deptid") String ppDeptId){
        try {
            return JsonResult.getSuccessResult(ddService.findBydeptId(ppDeptId));
        }catch(Exception e) {
            e.printStackTrace();
            logger.error("JiashuController->find_by_deptid:"+e.getMessage());
            return JsonResult.getErrorResult("查询失败！");
        }
    }

    @RequestMapping("daochu_by_deptid")
    public JsonResult<?> DaochuByDeptId(
            @RequestParam("deptid") String ppDeptId){
        try {
            return JsonResult.getSuccessResult(ddService.findBydeptId(ppDeptId));
        }catch(Exception e) {
            e.printStackTrace();
            logger.error("JiashuController->find_by_deptid:"+e.getMessage());
            return JsonResult.getErrorResult("查询失败！");
        }
    }

    @RequestMapping("find_jingshangchaheduibi_by_deptid_and_name")
    public JsonResult<?> findJingshangchaheduibiByDeptIdAndName(
            @RequestParam("deptid") String ppDeptId, @RequestParam("jiashuname") String ppJiashuName, @RequestParam("startindex") int ppStartIndex, @RequestParam("pagesize") int ppPageSize){
        try {
            return JsonResult.getSuccessResult(ddService.findJingshangchaheduibiByDeptIdAndName(ppDeptId,ppJiashuName,ppStartIndex,ppPageSize));
        }catch(Exception e) {
            e.printStackTrace();
            logger.error("JiashuController->findJingshangchaheduibiByDeptIdAndName:"+e.getMessage());
            return JsonResult.getErrorResult("查询失败！");
        }
    }
    @RequestMapping("find_zhenbieqingkuang_by_deptid_and_name")
    public JsonResult<?> findZhenbieqingkuangByDeptIdAndName(
            @RequestParam("deptid") String ppDeptId, @RequestParam("jiashuname") String ppJiashuName, @RequestParam("startindex") int ppStartIndex, @RequestParam("pagesize") int ppPageSize){
        try {
            return JsonResult.getSuccessResult(ddService.findZhenbieqingkuangByDeptIdAndName(ppDeptId,ppJiashuName,ppStartIndex,ppPageSize));
        }catch(Exception e) {
            e.printStackTrace();
            logger.error("JiashuController->findZhenbieqingkuangByDeptIdAndName:"+e.getMessage());
            return JsonResult.getErrorResult("查询失败！");
        }
    }


}
